<html>
<head><title>WavPlayer - flash wav/au player for arbitrary samplerate and PCM/G711 codecs</title>
<script>
function getPlayer(pid) {
	var obj = document.getElementById(pid);
	if (obj.doPlay) return obj;
	for(i=0; i<obj.childNodes.length; i++) {
		var child = obj.childNodes[i];
		if (child.tagName == "EMBED") return child;
	}
}
function doPlay(fname) {
	var player = getPlayer('haxe');
	player.doPlay(fname);
}
function doStop() {
	var player = getPlayer('haxe');
	player.doStop();
}
function setVolume(v) {
	var player = getPlayer('haxe');
	player.setVolume(v);
}
function setPan(p) {
	var player = getPlayer('haxe');
	player.setPan(p);
}
var SoundLen = 0;
var SoundPos = 0;
var Last = undefined;
var State = "STOPPED";
var Timer = undefined;
function getPerc(a, b) {
	return ((b==0?0.0:a/b)*100).toFixed(2);
}
function FileLoad(bytesLoad, bytesTotal) {
	document.getElementById('InfoFile').innerHTML = "Loaded "+bytesLoad+"/"+bytesTotal+" bytes ("+getPerc(BytesLoad,BytesTotal)+"%)";
}
function SoundLoad(secLoad, secTotal) {
	document.getElementById('InfoSound').innerHTML = "Available "+secLoad.toFixed(2)+"/"+secTotal.toFixed(2)+" seconds ("+getPerc(secLoad,secTotal)+"%)";
	SoundLen = secTotal;
}
var InfoState = undefined;
function Inform() {
	if (Last != undefined) {
		var now = new Date();
		var interval = (now.getTime()-Last.getTime())/1000;
		SoundPos += interval;
		Last = now;
	}
	InfoState.innerHTML = State + "("+SoundPos.toFixed(2)+"/"+SoundLen.toFixed(2)+") sec ("+getPerc(SoundPos,SoundLen)+"%)";
}
function SoundState(state, position) {
	if (position != undefined) SoundPos = position;
	if (State != "PLAYING" && state=="PLAYING") {
		Last = new Date();
		Timer = setInterval(Inform, 100);
		Inform();
	} else
	if (State == "PLAYING" && state!="PLAYING") {
		clearInterval(Timer);
		Timer = undefined;
		Inform();
	}
	State = state;
	Inform();
}
function init() {
	var player = getPlayer('haxe');
	if (!player || !player.attachHandler) setTimeout(init, 100); // Wait for load
	else {
		player.attachHandler("progress", "FileLoad");
		player.attachHandler("PLAYER_LOAD", "SoundLoad");
		player.attachHandler("PLAYER_BUFFERING", "SoundState", "BUFFERING");
		player.attachHandler("PLAYER_PLAYING", "SoundState", "PLAYING");
		player.attachHandler("PLAYER_STOPPED", "SoundState", "STOPPED");
		player.attachHandler("PLAYER_PAUSED", "SoundState", "PAUSED");
		InfoState = document.getElementById('InfoState')
		Inform();
	}
}
</script>
</head>
<body bgcolor="#dddddd" onload="init()">

<a href="javascript:doPlay()">doPlay()</a>
<a href="javascript:doPlay('test.gsm')">doPlay('test.gsm')</a>
<a href="javascript:doPlay('test.au')">doPlay('test.au')</a>
<a href="javascript:doPlay('direct-5683.au')">doPlay('direct-5683.au')</a>
<a href="javascript:doStop()">doStop()</a>
<br />
<a href="javascript:setVolume(5.0)">Volume 500%</a>
<a href="javascript:setVolume(2.0)">Volume 200%</a>
<a href="javascript:setVolume(1.0)">Volume 100%</a>
<a href="javascript:setVolume(0.5)">Volume 50%</a>
<a href="javascript:setVolume(0.1)">Volume 10%</a>
<a href="javascript:setVolume(0.0)">Volume 0% (mute)</a>
<br />
<a href="javascript:setPan(0.0)">Balance: center</a>
<a href="javascript:setPan(-1.0)">Balance: left</a>
<a href="javascript:setPan(1.0)">Balance: right</a>
<br/>

<div id="InfoFile"></div>
<div id="InfoSound"></div>
<div id="InfoState"></div>
<object    classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
		width="300"
	height="20"
	id="haxe"
	align="middle">
<param name="movie" value="wavplayer.swf?gui=full&h=20&w=300&sound=test-vf-44100.au&"/>
<param name="allowScriptAccess" value="always" />
<param name="quality" value="high" />
<param name="scale" value="noscale" />
<param name="salign" value="lt" />
<param name="bgcolor" value="#dddddd"/>
<embed src="wavplayer.swf?gui=full&h=20&w=300&sound=test-vf-44100.au&"
	   bgcolor="#dddddd"
	   width="300"
	   height="20"
	   name="haxe"
	   quality="high"
	   align="middle"
	   scale="noscale"
	   allowScriptAccess="always"
	   type="application/x-shockwave-flash"
	   pluginspage="http://www.macromedia.com/go/getflashplayer"
/>
</object>
</body>
</html>
